//
//  HWMineSaveMoneyCardCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/8/23.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWMineSaveMoneyCardCell: UICollectionViewCell {
    var bgImageView:UIImageView!
    var contentLabel:UILabel!
    var openBgView:UIView!
    var openLabel:UILabel!
    
    var model:HWMineShengQianKaModel? {
        didSet {
            bgImageView.kf.setImage(with: URL(string: model?.bg ?? ""))
            contentLabel.text = model?.text
            
            if model?.shengqianka == false {
                openLabel.text = "未开通"
            } else {
                openLabel.text = "还有\(model?.day ?? "")天到期"
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWMineSaveMoneyCardCell {
    private func initUI() -> Void {
        bgImageView = UIImageView()
        bgImageView.image = UIImage(named: "saveMoneyCard")
        bgImageView.backgroundColor = .clear
        bgImageView.layer.masksToBounds = true
        contentView.addSubview(bgImageView)
        
        contentLabel = HWLabel.createLabel(title: "", color: "#888888", font: 11*widthScale)
        contentView.addSubview(contentLabel)
        
        openBgView = UIView()
        openBgView.backgroundColor = .colorWithHexString(hexString: "#232323")
        openBgView.layer.cornerRadius = 11*widthScale
        openBgView.layer.masksToBounds = true
        contentView.addSubview(openBgView)
        
        openLabel = HWLabel.createBoldLabel(title: "未开通", color: "#F2C36E", font: 11*widthScale)
        openBgView.addSubview(openLabel)
    }
    
    private func initFrame() -> Void {
        bgImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(12*widthScale)
            make.top.equalTo(37*widthScale)
            make.height.equalTo(15*widthScale)
        }
        
        openBgView.snp.makeConstraints { make in
            make.left.equalTo(11*widthScale)
            make.bottom.equalTo(-5*widthScale)
            make.height.equalTo(22*widthScale)
        }
        
        openLabel.snp.makeConstraints { make in
            make.left.equalTo(15*widthScale)
            make.right.equalTo(-15*widthScale)
            make.centerY.equalToSuperview()
        }
    }
}
